package edu.cmu.fithub.formbeans;

import java.util.ArrayList;
import java.util.List;

import org.mybeans.form.FormBean;

public class CommentForm extends FormBean {

	private String comment;
	private int postId;

	public String getComment() {
		return comment;
	}

	public void setComment(String comment) {
		this.comment = comment;
	}

	public List<String> getValidationErrors() {
		List<String> errors = new ArrayList<String>();

		if (comment == null || comment.length() == 0) {
			errors.add("Comment is required");
		} else if (comment.matches(".*[<>].*")) {
			errors.add("Comment may not contain angle brackets");
			comment = comment.replaceAll(">", "&gt;");
			comment = comment.replaceAll("<", "&lt;");
		}
		return errors;
	}

	public int getPostId() {
		return postId;
	}

	public void setPostId(int postId) {
		this.postId = postId;
	}
}
